package com.chapter14.Homework.homework03;

import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Set;

/**
 * @author 宋鑫宇
 * @version 1.0
 */
public class Homework03 {
    public static void main(String[] args) {
        HashMap m = new HashMap();
        m.put("jack",650);
        m.put("tom",1200);
        m.put("smith",2900);

        m.replace("jack",2600);
//        System.out.println(m);
        Set set = m.keySet();
        for (Object o : set) {
            m.put(o,(Integer)m.get(o)+100);
        }
        System.out.println("Key迭代器");
        Iterator iterator = set.iterator();
        while (iterator.hasNext()) {
            Object next =  iterator.next();
            System.out.println(next + "=" + m.get(next));
        }
//        System.out.println(m);
        System.out.println("Key增强for");
        for (Object o : set) {
            System.out.println(o + "=" + m.get(o));
        }
        System.out.println("value迭代器");
        Collection values = m.values();
        Iterator iterator1 = values.iterator();
        while (iterator1.hasNext()) {
            Object next = iterator1.next();
            System.out.println(next);
        }
        System.out.println("value增强for");
        for (Object o :values) {
            System.out.println(o);
        }
        System.out.println("Entry迭代器");
        Set set1 = m.entrySet();
        Iterator iterator2 = set1.iterator();
        while (iterator2.hasNext()) {
            Object next =  iterator2.next();
            System.out.println(next);
        }
        System.out.println("Entry增强for");
        for (Object o : set1) {
            System.out.println(o);
        }

    }
}

